package astra.client.models;

import astra.client.services.HasId;
import com.google.gwt.user.client.rpc.IsSerializable;

import java.util.Date;
import java.util.Map;

/**
 * @author Kotelnikov Dmitry <a href="mailto:dimonnot@mail.ru"/>
 */
public class Employee implements IsSerializable, HasId {
	public enum Access {
        DENIED(false, true),
		VIEW_OWN(false, true),
		EDIT_OWN(true, true),
		VIEW_ALL(false, true),
		EDIT_ALL(true, true);

		private boolean editAllowed;
		private boolean onlyOwn;

		Access(boolean editAllowed, boolean onlyOwn) {
			this.editAllowed = editAllowed;
			this.onlyOwn = onlyOwn;
		}

        public boolean isEditAllowed() {
            return editAllowed;
        }

        public boolean isOnlyOwn() {
            return onlyOwn;
        }
    }

	private int id;
	private String login;
	private String name;
    private String groupName;
    private int groupId;
    private String phone;
    private String address;
	private Date lastVisitDate;
	private Map<String, Access> permissions;

	public Employee() {

	}

	public Employee(int id, String login, String name, int groupId,
            Date lastVisitDate, String groupName, String phone, String address,
            Map<String, Access> permissions) {
		this.id = id;
		this.login = login;
		this.name = name;
		this.lastVisitDate = lastVisitDate;
		this.permissions = permissions;
        this.groupName = groupName;
        this.groupId = groupId;
        this.phone = phone;
        this.address = address;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getLogin() {
		return login;
	}

	public void setLogin(String login) {
		this.login = login;
	}

	public Date getLastVisitDate() {
		return lastVisitDate;
	}

	public synchronized void setLastVisitDate(Date lastVisitDate) {
		this.lastVisitDate = lastVisitDate;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Map<String, Access> getPermissions() {
		return permissions;
	}

	public void setPermissions(Map<String, Access> permissions) {
		this.permissions = permissions;
	}

    public int getGroupId() {
        return groupId;
    }

    public void setGroupId(int groupId) {
        this.groupId = groupId;
    }

    public String getGroupName() {
        return groupName;
    }

    public void setGroupName(String groupName) {
        this.groupName = groupName;
    }

    public String getPhone() {
        return phone;
    }

    public Access getAccess(String page) {
        return permissions.get(page);
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }
}
